# -*- coding: utf-8 -*-
# @Time : 2023/12/10 00:06
# @Author : Lpb
# @File : pro1.py
# 1、创建文件data.txt 文件共100行，每行存放一个1~100之间的整数（random）
# 方法一
import random
with open(file='data.txt', mode='w', encoding='utf-8') as file:
    for n in range(100):
        num = str(random.randint(1, 100))+'\n'
        file.write(num)
print(f"文件{num}已创建并写入100行随机整数。")
# 方法二：
import  random
f = open('data.txt', mode='w', encoding='utf-8')
for i in range(100):
    num = random.randint(1, 100)
    f.write(str(num)+'\n')
    print(f"文件{num}已创建并写入100行随机整数。")
f.close()




# import random
#
# with open(file='./data.txt',mode= "w", encoding='utf-8') as file:
#     for i in range(100):
#         # 生成1到100之间的随机整数
#         line = str(random.randint(1, 100)) + "\n"
#         # 写入文件
#         file.write(line)
#
# print(f"文件 {file} 已创建并写入100行随机整数。")
